
<template>
	<el-dialog class="set_dialog" width="500px" :title="title" :visible.sync="dialogVisible" :close-on-click-modal="false">
	  <el-form ref="ruleForm" class="ruleForm" :model="form" :rules="rules" label-width="100px">
	    <el-form-item label="商品品牌" prop="name">
	      <el-input v-model="form.name" placeholder="请输入商品品牌名称"></el-input>
	    </el-form-item>
	  </el-form>
	  <div slot="footer" class="dialog-footer">
	    <el-button size="small" @click="dialogVisible = false">取 消</el-button>
	    <el-button size="small" type="primary" @click="submit">确 定</el-button>
	  </div>
	</el-dialog>
</template>

<script>
	import { insertBrand, updateBrand } from '@/api/goods'
export default {
  props:['editItem'],
  data() {
    return {
      form: {
        name: '',
      },
      dialogVisible: false,
      goodsId: null,
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        if(this.title=='编辑品牌'){
          this.form.name=this.editItem.name
        }else{
          this.form.name=''
        }
      }
    }
  },
  methods: {
    submit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          if(this.title=='添加品牌'){
            insertBrand(this.form).then(res=>{
              this.dialogVisible=false
              this.$emit('getList')
              this.$message({
                message: '添加成功',
                type: 'success'
              })
					  })
          }else{
            let params={
              id:this.editItem.id,
              name:this.form.name
            }
            updateBrand(params).then(res=>{
              this.dialogVisible=false
              this.$emit('getList')
              this.$message({
                message: '编辑成功',
                type: 'success'
              })
					  })
          }
					
        } else {
          this.$message({
            message: '请检查表单错误',
            type: 'error'
          })
          return false
        }
      })
    }
  }
}
</script>

<style>
</style>